package zuoye;

import java.util.*;

public class app {
    public static void main(String[] args) {//界面
        Scanner sc=new Scanner(System.in);
        while (true) {
            System.out.println("1--------密码有效性检查");
            System.out.println("2--------运算表达式求解");
            System.out.println("3--------学生成绩统计");
            System.out.println("4--------退出");
            System.out.println("请输入你的选择");
            int choose=sc.nextInt();
            switch(choose){
                case 1-> CheckPassword();//密码有效性检查
                case 2->Operation();//运算表达式求解
                case 3-> StudentGrade();//学生成绩统计
                case 4->{
                    System.out.println("谢谢");
                    System.exit(0);
                }
                default->{
                    System.out.println("没有这个选项，请重新输入");
                }
            }
        }
    }
    public static void CheckPassword(){
        System.out.println("请输入密码");
        Scanner sc=new Scanner(System.in);
        String password=sc.next();
        boolean flag=true;
        int lowcount=0;
        int uppercount=0;
        if((password.length()<8)||(password.length()>15)){//8到15 之间
            flag= false;
        }
        for(int i=0;i<password.length();i++){
            char chs=password.charAt(i);
            if((chs==' ')||(chs<'0')&&(chs>'9')){//不为空格，至少一个数字
                flag= false;
            }
            if((chs>='a')&&(chs<='z')){//计数小写字母
                lowcount++;
            }
            else if((chs>='A')&&(chs<='Z')){//计数大写字母
                uppercount++;
            }
        }
        if((lowcount==0)||(uppercount==0)){//判断至少要有一个大写和小写
           flag=false;
        }
        if(flag){
            System.out.println("密码符合，欢迎");
        }else{
            System.out.println("密码不符合，请重新输入");
        }
    }
    public static void Operation(){//对表达式进行判断
        System.out.println("请输入表达式");
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        if(str.substring(0,3).equals("add")){
            System.out.printf("%.1f",getnumber1(str)+getnumber2(str));
            System.out.println();
        }
        else if(str.substring(0,3).equals("sub")){
            System.out.printf("%.1f",getnumber1(str)-getnumber2(str));
            System.out.println();
        }
        else if(str.substring(0,3).equals("max")){
            System.out.println(Math.max(getnumber1(str),getnumber2(str)));
            System.out.println();

        }
        else if(str.substring(0,3).equals("min")){
            System.out.println(Math.min(getnumber1(str),getnumber2(str)));
            System.out.println();
        }
        else if(str.substring(0,8).equals("doubleMe")){
            System.out.println(2*getnumber3(str));
        }
        else{
            System.out.println("请输入正确的表达式");
        }

    }
    public static double getnumber1(String str){
        String num=str.substring(str.indexOf("(")+1,str.indexOf(","));
        return Double.parseDouble(num);
    }//获取括号里的数字
    public static double  getnumber2(String str){
        String num=str.substring(str.indexOf(",")+1,str.indexOf(")"));
        return Double.parseDouble(num);
    }//获取括号里的数字
    public static int getnumber3(String str){
        return Integer.parseInt(str.substring(str.indexOf("(")+1,str.indexOf(")")));
    }//获取括号里的数字
    public static void StudentGrade(){
        Vector<Student> vs = new Vector<Student>();
        String[] st = new String[3];
        Scanner in = new Scanner(System.in);
        System.out.println("请输入学生基本信息：");
        String s = in.next();
        while(!s.equals("end"))
        {
            st = s.split(",");
            Student S = new Student();
            S.setSno(st[0]);
            S.setName(st[1]);
            S.setSex(st[2]);
            vs.add(S);
            s = in.next();
        }
        System.out.println("请输入学生成绩：");
        String name = in.next();
        String[] str = new String[3];
        while(!name.equals("end"))
        {
            str = name.split(",");
            for(Student a : vs)
            {
                if(a.getSno().equals(str[0]))
                {
                    a.getM1().put(str[1],str[2]);
                    a.setSum(Double.valueOf(a.getSum())+Double.valueOf(str[2]));
                }
            }
            name = in.next();

        }
        double Javasum=0,Websum=0,Csum=0;
        System.out.println("按学生统计：");
        System.out.println("学号  姓名  性别  平均分");
        for(Student b : vs)
        {
            System.out.println(b.getSno()+" "+b.getName()+" "+b.getSex()+" "+String.format("%.0f",b.getSum()/(b.getM1().size())));
            Iterator<Map.Entry<String, String>> iterator = b.getM1().entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, String> entry = iterator.next();
                String key = entry.getKey();
                String value = entry.getValue();
                if(key.equals("Java")) {
                    Javasum += Double.valueOf(value);
                } else if (key.equals("网络")) {
                    Websum += Double.valueOf(value);
                }else if(key.equals("C")) {
                    Csum += Double.valueOf(value);
                }
            }
        }
        System.out.println("按照课程统计：");
        System.out.println("课程: 平均分");
        System.out.println("Java: "+ String.format("%.0f",Javasum/((vs.get(0).getM1()).size()+1)));
        System.out.println("网络: "+ String.format("%.0f",Websum/((vs.get(0).getM1()).size()+1)));
        System.out.println("C: "+ String.format("%.0f",Csum/((vs.get(0).getM1()).size()+1)));
    }

}